<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <script src="https://gw.alipayobjects.com/os/lib/antv/g2/4.0.11/dist/g2.min.js"></script>
    <script src="https://unpkg.com/@antv/data-set"></script>
    <script src="https://cdn.bootcss.com/moment.js/2.24.0/moment.min.js"></script>
  </head>

  <body>
    <!-- 创建图表容器 -->
    <div id="c1"></div>
    <script>
      const data = [
        { month: "一月", num: 275 },
        { month: "二月", num: 115 },
        { month: "三月", num: 120 },
        { month: "四月", num: 350 },
        { month: "五月", num: 150 },
      ];

      // Step 1: 创建 Chart 对象
      const chart = new G2.Chart({
        container: "c1", // 指定图表容器 ID
        autoFit: true,
        height: 500,
      });

      // Step 2: 载入数据源
      chart.data(data);

      // Step 3：创建图形语法，绘制柱状图
      chart
        .interval()
        .position("month*num")
        .color('month')
        .label("percent", {
          content: (data) => {
            return `${data.num}`;
          },
        }) 
      // Step 4: 渲染图表
      chart.render();
    </script>
  </body>
</html>
